package com.pension.servlet.room;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pension.model.dao.RoomDao;
import com.pension.model.dto.Room;

@WebServlet("/room/editform.action")
public class RoomEditFormServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String roomnumber = request.getParameter("roomnumber");
		if (roomnumber == null || roomnumber.length() == 0) {
			response.sendRedirect("admin.action");
			return;
		}
		
		RoomDao dao = new RoomDao();
		Room room = dao.getRoomByRoomNumber(Integer.parseInt(roomnumber));
		

		if (room == null) {
			response.sendRedirect("admin.action");
			return;
		}
		
		request.setAttribute("room", room);
		
		RequestDispatcher dispatcher = 
			request.getRequestDispatcher("/WEB-INF/views/room/roomeditform.jsp");

		dispatcher.forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
